package com.flurry.android;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
import android.webkit.WebChromeClient;
import android.webkit.WebChromeClient.CustomViewCallback;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

final class ft extends p
  implements DialogInterface.OnKeyListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, MediaPlayer.OnPreparedListener, au
{
  private Context Q;
  private View cJ;
  private int cK;
  private FrameLayout cM;
  private WebView eq;
  private WebViewClient er;
  private WebChromeClient es;
  private FlurryAds fI;
  private ProgressDialog fu;
  private MediaController fx;
  private gk hN;
  private boolean hO;
  private boolean hP;
  private WebChromeClient.CustomViewCallback hQ;
  private Dialog hR;
  private int hS;
  private Dialog hT;
  private FrameLayout hU;
  private boolean hV;
  private boolean hW;
  private boolean hX;
  private AlertDialog hY;
  private List<AdFrame> hZ;
  private aa hk;
  private boolean ia;
  private Map<String, AdUnit> ib;
  private Map<String, cw> ic;
  private Activity id;
  private String ie = null;
  private List<String> jdField_if;
  private final String p = getClass().getSimpleName();

  ft(Context paramContext, FlurryAds paramFlurryAds, cw paramcw, AdUnit paramAdUnit, int paramInt)
  {
    super(paramContext, paramFlurryAds, paramcw);
    this.Q = paramContext;
    if ((paramContext instanceof Activity))
      this.id = ((Activity)paramContext);
    setClickable(i);
    this.T = paramAdUnit;
    this.U = paramInt;
    this.S = paramcw;
    if (this.T != null)
    {
      this.hZ = this.T.getAdFrames();
      if (this.T.getCombinable().intValue() != i)
        break label228;
    }
    while (true)
    {
      this.ia = i;
      if (this.ia)
      {
        this.ic = new HashMap();
        this.ib = new HashMap();
        this.ic.put(paramcw.aA(), paramcw);
        this.ib.put(((AdFrame)paramAdUnit.getAdFrames().get(0)).getAdGuid().toString(), paramAdUnit);
      }
      this.fI = paramFlurryAds;
      this.hk = this.fI.hk;
      this.T = this.T;
      this.S = this.S;
      this.jdField_if = new LinkedList();
      return;
      label228: int j = 0;
    }
  }

  private cw I(String paramString)
  {
    cw localcw1;
    if (this.ic == null)
      localcw1 = null;
    do
    {
      return localcw1;
      localcw1 = (cw)this.ic.get(paramString);
    }
    while (localcw1 != null);
    cw localcw2 = ct.a(this.fI, paramString);
    this.ic.put(paramString, localcw2);
    return localcw2;
  }

  private AdUnit J(String paramString)
  {
    if (this.ib == null)
      return null;
    return (AdUnit)this.ib.get(paramString);
  }

  private void a(int paramInt1, int paramInt2)
  {
    if (this.hT == null)
      return;
    new StringBuilder().append("collapse(").append(paramInt1).append(",").append(paramInt2).append(")").toString();
    if ((this.hT != null) && (this.hT.isShowing()))
    {
      this.hT.hide();
      this.hT.setOnDismissListener(null);
      this.hT.dismiss();
    }
    this.hT = null;
    fd.a(this.id, this.hS);
    if (this.hU != null)
    {
      if ((this.eq != null) && (-1 != this.hU.indexOfChild(this.eq)))
        this.hU.removeView(this.eq);
      this.hU = null;
    }
    if ((this.eq != null) && (this.eq.getParent() == null))
      addView(this.eq);
    this.R.onCloseFullScreen(this.Q, this.T.getAdSpace().toString());
  }

  private List<AdUnit> b(int paramInt1, int paramInt2)
  {
    List localList = this.hk.b(this.Q, this.T.getAdSpace().toString(), paramInt2);
    Iterator localIterator = localList.iterator();
    while (localIterator.hasNext())
    {
      AdUnit localAdUnit = (AdUnit)localIterator.next();
      if (localAdUnit.getAdFrames().size() > 0)
        this.ib.put(((AdFrame)localAdUnit.getAdFrames().get(0)).getAdGuid().toString(), localAdUnit);
    }
    return localList;
  }

  private AdFrame bA()
  {
    return (AdFrame)this.hZ.get(this.U);
  }

  private v bB()
  {
    try
    {
      ViewParent localViewParent = getParent();
      if (localViewParent != null)
      {
        v localv = (v)localViewParent;
        return localv;
      }
      return null;
    }
    catch (ClassCastException localClassCastException)
    {
      cy.g(this.p, "AdUnityView parent not a BannerHolder:" + localClassCastException.getMessage());
    }
    return null;
  }

  private String bx()
  {
    return bA().getDisplay().toString();
  }

  private String by()
  {
    return bA().getAdSpaceLayout().getFormat().toString();
  }

  private String j(List<AdUnit> paramList)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("'{\"adComponents\":[");
    String str1 = this.eq.getUrl();
    String str2 = UriUtils.root(str1);
    String str3 = UriUtils.relativize(str2, str1);
    Iterator localIterator = paramList.iterator();
    while (localIterator.hasNext())
    {
      String str4 = ((AdFrame)((AdUnit)localIterator.next()).getAdFrames().get(0)).getContent().toString();
      if ((!TextUtils.isEmpty(str4)) && (!TextUtils.isEmpty(str3)) && (str3 != str2))
        str4 = str4.replace(str2, str3);
      localStringBuilder.append(fl.G(str4));
      if (localIterator.hasNext())
        localStringBuilder.append(",");
    }
    localStringBuilder.append("]}'");
    return localStringBuilder.toString();
  }

  final void a(String paramString, Map<String, String> paramMap, AdUnit paramAdUnit, cw paramcw, int paramInt1, int paramInt2)
  {
    new StringBuilder().append("fireEvent(event=").append(paramString).append(",params=").append(paramMap).append(")").toString();
    this.R.onEvent(new gt(paramString, paramMap, this.Q, paramAdUnit, paramcw, paramInt1), this, paramInt2);
  }

  final boolean a(View paramView)
  {
    ViewParent localViewParent = paramView.getParent();
    return (localViewParent != null) && (localViewParent == this);
  }

  final int bw()
  {
    return bA().getBinding().intValue();
  }

  final boolean bz()
  {
    return by().equals("takeover");
  }

  public final void initLayout(Context paramContext)
  {
    new StringBuilder().append("initLayout: ad creative layout: {width = ").append(bA().getAdSpaceLayout().getAdWidth()).append(", height = ").append(bA().getAdSpaceLayout().getAdHeight()).append("}").toString();
    removeAllViews();
    setFocusable(true);
    setFocusableInTouchMode(true);
    switch (bw())
    {
    default:
      a("renderFailed", Collections.emptyMap(), this.T, this.S, this.U, 0);
      return;
    case 3:
      if (this.hN == null)
      {
        this.hN = new gk(paramContext);
        this.hN.setOnPreparedListener(this);
        this.hN.setOnCompletionListener(this);
        this.hN.setOnErrorListener(this);
        this.fx = new MediaController(paramContext);
        this.hN.setMediaController(this.fx);
      }
      this.hN.setVideoURI(Uri.parse(bx()));
      cy.c(this.p, "URI: " + Uri.parse(bx()).toString());
      this.hN.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
      addView(this.hN);
      ((RelativeLayout)this.hN.getParent()).setGravity(17);
      this.fu = new ProgressDialog(paramContext);
      this.fu.setProgressStyle(0);
      this.fu.setMessage("Loading...");
      this.fu.setCancelable(true);
      this.fu.setOnKeyListener(this);
      this.fu.show();
      return;
    case 1:
    case 2:
    }
    if (this.eq == null)
    {
      this.eq = new WebView(paramContext);
      this.eq.getSettings().setJavaScriptEnabled(true);
      this.eq.setVerticalScrollBarEnabled(false);
      this.eq.setHorizontalScrollBarEnabled(false);
      this.eq.setBackgroundColor(0);
      this.eq.clearCache(false);
      this.es = new co(this);
      this.eq.setWebChromeClient(this.es);
      this.er = new gg(this);
      this.eq.setWebViewClient(this.er);
    }
    a("rendered", Collections.emptyMap(), this.T, this.S, this.U, 0);
    if (bw() == 1)
      if (this.ie != null)
        this.eq.loadUrl(this.ie);
    while (true)
    {
      this.eq.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
      return;
      String str = bx();
      this.eq.loadUrl(str);
      continue;
      if (bw() == 2)
        this.eq.loadDataWithBaseURL("base://url/", bx(), "text/html", "utf-8", "base://url/");
    }
  }

  public final void onCompletion(MediaPlayer paramMediaPlayer)
  {
    a("videoCompleted", Collections.emptyMap(), this.T, this.S, this.U, 0);
  }

  public final boolean onError(MediaPlayer paramMediaPlayer, int paramInt1, int paramInt2)
  {
    if ((this.fu != null) && (this.fu.isShowing()))
      this.fu.dismiss();
    a("renderFailed", Collections.emptyMap(), this.T, this.S, this.U, 0);
    removeView(this.hN);
    return false;
  }

  public final boolean onKey(DialogInterface paramDialogInterface, int paramInt, KeyEvent paramKeyEvent)
  {
    new StringBuilder().append("onkey,keycode=").append(paramInt).append(",event=").append(paramKeyEvent.getAction()).toString();
    ProgressDialog localProgressDialog = this.fu;
    boolean bool = false;
    if (paramDialogInterface == localProgressDialog)
    {
      bool = false;
      if (paramInt == 4)
      {
        int i = paramKeyEvent.getAction();
        bool = false;
        if (i == 0)
        {
          a("adWillClose", Collections.emptyMap(), this.T, this.S, this.U, 0);
          paramDialogInterface.dismiss();
          bool = true;
        }
      }
    }
    return bool;
  }

  public final void onPrepared(MediaPlayer paramMediaPlayer)
  {
    if (bw() == 3)
    {
      if (this.fu.isShowing())
        this.fu.dismiss();
      if (((this.hY == null) || (!this.hY.isShowing())) && (this.hN != null) && (this.hO))
        this.hN.start();
      a("rendered", Collections.emptyMap(), this.T, this.S, this.U, 0);
      a("videoStart", Collections.emptyMap(), this.T, this.S, this.U, 0);
    }
  }

  public final void pause()
  {
    if ((this.eq != null) && (n.SDK_INT >= 11))
      this.eq.onPause();
    if ((this.hN != null) && (bw() == 3))
      this.hN.pause();
    this.hO = false;
  }

  public final void performAction$3deb3ec3(y paramy, FlurryAds paramFlurryAds, int paramInt)
  {
    String str1 = paramy.bi;
    gt localgt = paramy.bk;
    Map localMap = paramy.bj;
    if (paramInt > 10)
      new StringBuilder().append("Maximum depth for event/action loop exceeded when performing action:").append(str1).append(",").append(localMap).append(",triggered by:").append(localgt.jf).toString();
    String str10;
    do
    {
      return;
      if (!localgt.jf.equals("clicked"))
        break;
      str10 = (String)localgt.bj.get("noop");
    }
    while ((str10 != null) && (str10.equals("true")));
    new StringBuilder().append("performAction(action=").append(str1).append(",params=").append(paramy.bj).append(",triggering event=").append(localgt.jf).append(")").toString();
    int i12;
    String str6;
    if (str1.equals("nextFrame"))
    {
      i12 = 1 + this.U;
      str6 = (String)localMap.get("offset");
      if (str6 != null)
      {
        if (str6.equals("next"))
          i12 = 1 + this.U;
      }
      else
      {
        label231: if (this.ia)
          break label548;
        if ((i12 != this.U) && (i12 < this.hZ.size()))
        {
          AdFrame localAdFrame = (AdFrame)this.T.getAdFrames().get(i12);
          String str8 = by();
          String str9 = localAdFrame.getAdSpaceLayout().getFormat().toString();
          if (str9.equals(str8))
            break label531;
          if (str9.equals("takeover"))
          {
            this.fI.b(this.S);
            this.fI.a(this.T);
            Intent localIntent = new Intent(this.Q, FlurryFullscreenTakeoverActivity.class);
            localIntent.putExtra("frameIndex", i12);
            this.fI.a(this.Q, localIntent, this.T.getAdSpace().toString());
          }
        }
      }
    }
    label393: label531: label548: label1264: int n;
    int i1;
    while (true)
    {
      while (true)
      {
        if ((!this.jdField_if.contains(paramy.bk.jf)) || (this.eq == null))
          break label2013;
        this.eq.loadUrl("javascript:flurryadapter.callComplete('" + paramy.bk.jf + "');");
        this.jdField_if.remove(paramy.bk.jf);
        return;
        if (str6.equals("current"))
          break;
        try
        {
          int i13 = Integer.parseInt(str6);
          i12 = i13;
        }
        catch (NumberFormatException localNumberFormatException3)
        {
          new StringBuilder().append("caught: ").append(localNumberFormatException3.getMessage()).toString();
        }
      }
      break label231;
      this.U = i12;
      initLayout(this.Q);
      continue;
      String str7 = (String)paramy.bk.bj.get("guid");
      if (str7 != null)
      {
        this.T = J(str7);
        this.hZ = this.T.getAdFrames();
        this.S = paramy.bk.S;
        if (bz())
        {
          this.fI.a(this.T);
          this.fI.b(this.S);
        }
        this.U = i12;
        this.ia = false;
        initLayout(this.Q);
        continue;
        if (str1.equals("closeAd"))
        {
          if (bz())
            try
            {
              ((Activity)this.Q).finish();
            }
            catch (ClassCastException localClassCastException)
            {
              new StringBuilder().append("caught class cast exception: ").append(localClassCastException).toString();
            }
        }
        else
        {
          if (str1.equals("notifyUser"))
          {
            AlertDialog.Builder localBuilder = new AlertDialog.Builder(this.Q);
            String str2;
            String str3;
            if ((localMap.containsKey("message")) && (localMap.containsKey("confirmDisplay")) && (localMap.containsKey("cancelDisplay")))
            {
              str2 = (String)localMap.get("message");
              str3 = (String)localMap.get("confirmDisplay");
            }
            for (String str4 = (String)localMap.get("cancelDisplay"); ; str4 = "OK")
            {
              localBuilder.setMessage(str2).setCancelable(false).setPositiveButton(str4, new bk(this, localgt, paramInt)).setNegativeButton(str3, new bh(this, localgt, paramInt));
              this.hY = localBuilder.create();
              if ((this.hN != null) && (bw() == 3))
                this.hN.pause();
              this.hY.show();
              break;
              str2 = "Are you sure?";
              str3 = "Cancel";
            }
          }
          if (str1.equals("loadAdComponents"))
          {
            int i8 = 1;
            int i9 = 3;
            if ((localMap.containsKey("min")) && (localMap.containsKey("max")));
            try
            {
              int i10 = Integer.parseInt((String)localMap.get("min"));
              int i11 = Integer.parseInt((String)localMap.get("max"));
              i9 = i11;
              i8 = i10;
              this.T.getAdSpace().toString();
              List localList = b(i8, i9);
              if (localList.size() <= 0)
                break label1264;
              this.T.getAdSpace().toString();
              String str5 = j(localList);
              if (this.eq != null)
              {
                this.eq.loadUrl("javascript:(function() {var multiadwraps=document.getElementsByClassName('multiAdWrap');if(multiadwraps.length>0){var template=document.getElementsByClassName('multiAdWrap')[0];var compiled=Hogan.compile(template.innerHTML);template.innerHTML='';template.innerHTML=compiled.render(JSON.parse(" + str5 + "));}})();");
                this.eq.loadUrl("javascript:flurryadapter.callComplete();");
              }
              Iterator localIterator = localList.iterator();
              while (localIterator.hasNext())
              {
                AdUnit localAdUnit = (AdUnit)localIterator.next();
                HashMap localHashMap2 = new HashMap();
                localHashMap2.put("guid", ((AdFrame)localAdUnit.getAdFrames().get(0)).getAdGuid().toString());
                a("rendered", localHashMap2, localAdUnit, I(((AdFrame)localAdUnit.getAdFrames().get(0)).getAdGuid().toString()), 0, 0);
              }
            }
            catch (NumberFormatException localNumberFormatException2)
            {
              while (true)
              {
                i8 = 1;
                i9 = 3;
              }
            }
            if ((this.eq != null) && (!a(this.eq)))
            {
              addView(this.eq);
              continue;
              a("renderFailed", Collections.emptyMap(), this.T, this.S, this.U, 0);
            }
          }
          else if (str1.equals("doExpand"))
          {
            n = fl.q(this.Q);
            i1 = fl.r(this.Q);
            if ((!paramy.bk.bj.containsKey("width")) || (!paramy.bk.bj.containsKey("height")))
              break label2015;
          }
        }
      }
    }
    while (true)
    {
      try
      {
        int i6 = fl.b(this.Q, Integer.parseInt((String)paramy.bk.bj.get("width")));
        int i7 = fl.b(this.Q, Integer.parseInt((String)paramy.bk.bj.get("height")));
        i2 = i6;
        i3 = i7;
        new StringBuilder().append("expand to width = ").append(i2).append(" height = ").append(i3).toString();
        if (bB() != null)
        {
          a("clicked", Collections.emptyMap(), this.T, this.S, this.U, 0);
          if (this.hT == null)
          {
            new StringBuilder().append("expand(").append(i2).append(",").append(i3).append(")").toString();
            if ((this.eq != null) && (-1 != indexOfChild(this.eq)))
              removeView(this.eq);
            this.hS = this.id.getRequestedOrientation();
            if (this.hU == null)
            {
              this.hU = new FrameLayout(this.Q);
              this.hU.setBackgroundColor(-16777216);
              if ((this.eq != null) && (this.eq.getParent() == null))
                this.hU.addView(this.eq, new FrameLayout.LayoutParams(-1, -1, 17));
            }
            if (this.hT == null)
            {
              this.hT = new Dialog(this.Q, 16973834);
              s.a(this.hT.getWindow());
              this.hT.setContentView(this.hU, new ViewGroup.LayoutParams(-1, -1));
              this.hT.setOnDismissListener(new bj(this));
              this.hT.setCancelable(true);
              this.hT.show();
            }
            fd.a(this.id, fd.bf(), true);
            this.R.onOpenFullScreen(this.Q, this.T.getAdSpace().toString());
          }
        }
        if (!paramy.bk.bj.containsKey("url"))
          break label393;
        this.ie = ((String)paramy.bk.bj.get("url"));
        initLayout(this.Q);
      }
      catch (NumberFormatException localNumberFormatException1)
      {
        localNumberFormatException1.getMessage();
        int i4 = fl.q(this.Q);
        int i5 = fl.r(this.Q);
        i2 = i4;
        i3 = i5;
        continue;
      }
      if (str1.equals("doCollapse"))
      {
        int i = bA().getAdSpaceLayout().getAdWidth().intValue();
        int j = bA().getAdSpaceLayout().getAdHeight().intValue();
        int k = fl.b(this.Q, i);
        int m = fl.b(this.Q, j);
        if (this.ie != null)
        {
          this.ie = null;
          initLayout(this.Q);
        }
        if (bB() == null)
          break label393;
        a(k, m);
        break label393;
      }
      if (str1.equals("directOpen"))
      {
        HashMap localHashMap1 = new HashMap();
        localHashMap1.put("noop", "true");
        a("clicked", localHashMap1, this.T, this.S, this.U, 0);
      }
      this.R.performAction$3deb3ec3(paramy, paramFlurryAds, paramInt);
      break label393;
      label2013: break;
      label2015: int i2 = n;
      int i3 = i1;
    }
  }

  public final void resume()
  {
    this.hO = true;
    if ((this.eq != null) && (n.SDK_INT >= 11))
      this.eq.onResume();
    if ((this.hN != null) && (bw() == 3) && (this.fx != null))
      this.fx.show(0);
  }

  final boolean shouldRotate()
  {
    NetworkInfo localNetworkInfo = ((ConnectivityManager)this.Q.getSystemService("connectivity")).getActiveNetworkInfo();
    int i;
    int j;
    if ((localNetworkInfo != null) && (localNetworkInfo.isAvailable()) && (localNetworkInfo.isConnected()))
    {
      i = 1;
      if (this.hT == null)
        break label76;
      j = 1;
      label46: if (j != 0)
        break label87;
      if (this.hR == null)
        break label81;
    }
    label76: label81: for (int k = 1; ; k = 0)
    {
      if ((k != 0) || (i == 0))
        break label87;
      return true;
      i = 0;
      break;
      j = 0;
      break label46;
    }
    label87: return false;
  }

  public final void stop()
  {
    if (bw() == 3)
    {
      if ((this.fu != null) && (this.fu.isShowing()))
        this.fu.dismiss();
      if ((this.hN != null) && (this.hN.isPlaying()))
        this.hN.stopPlayback();
    }
    if (this.eq != null)
    {
      if ((this.cJ != null) && (this.es != null))
        this.es.onHideCustomView();
      if (this.hT != null)
        a(0, 0);
      removeView(this.eq);
      this.eq.stopLoading();
      if (n.SDK_INT >= 11)
        this.eq.onPause();
      this.eq.destroy();
      this.eq = null;
    }
    if (bz())
      a("adClosed", Collections.emptyMap(), this.T, this.S, this.U, 0);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.flurry.android.ft
 * JD-Core Version:    0.6.2
 */